package com.ruoyi.service;

import com.ruoyi.entity.SxfParkingSpace;
import com.ruoyi.mapper.SxfParkingSpaceMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bean.SxfParkingSpaceFrom;
import com.sxftech.resp.ResponseData;
/**
 * <p>
 * 车位信息表 服务实现类
 * </p>
 *
 * @author liuxing
 * @since 2020-10-28
 */
@Service
public class SxfParkingSpaceService extends ServiceImpl<SxfParkingSpaceMapper, SxfParkingSpace> {

	public ResponseData create(SxfParkingSpaceFrom sxfParkingSpace) {
		SxfParkingSpace entity = transformationFrom(sxfParkingSpace);
		this.save(entity);
		return ResponseData.success("新增成功");
	}
	
	public ResponseData modify(SxfParkingSpaceFrom sxfParkingSpace) {
		if(findById(sxfParkingSpace.getId())== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfParkingSpace entity = transformationFrom(sxfParkingSpace);
		entity.setId(sxfParkingSpace.getId());
		this.updateById(entity);
		return ResponseData.success("修改成功");
	}

	public SxfParkingSpace transformationFrom(SxfParkingSpaceFrom sxfParkingSpace) {
		SxfParkingSpace entity = new SxfParkingSpace();
		entity.setPlCode(sxfParkingSpace.getPlCode());
		entity.setSpaceCode(sxfParkingSpace.getSpaceCode());
		entity.setZoneCode(sxfParkingSpace.getZoneCode());
		entity.setPlZoneInZoneCode(sxfParkingSpace.getPlZoneInZoneCode());
		entity.setPropertyPerson(sxfParkingSpace.getPropertyPerson());
		entity.setUserPerson(sxfParkingSpace.getUserPerson());
		entity.setUserPhone(sxfParkingSpace.getUserPhone());
		entity.setNature(sxfParkingSpace.getNature());
		entity.setIsShare(sxfParkingSpace.getIsShare());
		entity.setSpaceType(sxfParkingSpace.getSpaceType());
		entity.setSpaceState(sxfParkingSpace.getSpaceState());
		entity.setRemark(sxfParkingSpace.getRemark());
		entity.setTransverseAxis(sxfParkingSpace.getTransverseAxis());
		entity.setPortraiAxis(sxfParkingSpace.getPortraiAxis());
		entity.setIsOccupy(sxfParkingSpace.getIsOccupy());
		entity.setSelfIsShare(sxfParkingSpace.getSelfIsShare());
		entity.setSpacePosition(sxfParkingSpace.getSpacePosition());
		entity.setDepartmentId(sxfParkingSpace.getDepartmentId());
		entity.setIsDeleted(sxfParkingSpace.getIsDeleted());
		entity.setPlatformIsShare(sxfParkingSpace.getPlatformIsShare());
		entity.setShareChangeTime(sxfParkingSpace.getShareChangeTime());
		entity.setReserveTempCount(sxfParkingSpace.getReserveTempCount());
		entity.setReserveTempMaxCount(sxfParkingSpace.getReserveTempMaxCount());
		entity.setRankDirection(sxfParkingSpace.getRankDirection());
		entity.setRankOrder(sxfParkingSpace.getRankOrder());
		entity.setCreator(sxfParkingSpace.getCreator());
		entity.setCreateTime(sxfParkingSpace.getCreateTime());
		entity.setModifier(sxfParkingSpace.getModifier());
		entity.setModifyTime(sxfParkingSpace.getModifyTime());
		entity.setSpaceId(sxfParkingSpace.getSpaceId());
		return entity;
	}

	public SxfParkingSpaceFrom transformationBean(SxfParkingSpace sxfParkingSpace) {
		SxfParkingSpaceFrom from = new SxfParkingSpaceFrom();
		from.setPlCode(sxfParkingSpace.getPlCode());
		from.setSpaceCode(sxfParkingSpace.getSpaceCode());
		from.setZoneCode(sxfParkingSpace.getZoneCode());
		from.setPlZoneInZoneCode(sxfParkingSpace.getPlZoneInZoneCode());
		from.setPropertyPerson(sxfParkingSpace.getPropertyPerson());
		from.setUserPerson(sxfParkingSpace.getUserPerson());
		from.setUserPhone(sxfParkingSpace.getUserPhone());
		from.setNature(sxfParkingSpace.getNature());
		from.setIsShare(sxfParkingSpace.getIsShare());
		from.setSpaceType(sxfParkingSpace.getSpaceType());
		from.setSpaceState(sxfParkingSpace.getSpaceState());
		from.setRemark(sxfParkingSpace.getRemark());
		from.setTransverseAxis(sxfParkingSpace.getTransverseAxis());
		from.setPortraiAxis(sxfParkingSpace.getPortraiAxis());
		from.setIsOccupy(sxfParkingSpace.getIsOccupy());
		from.setSelfIsShare(sxfParkingSpace.getSelfIsShare());
		from.setSpacePosition(sxfParkingSpace.getSpacePosition());
		from.setDepartmentId(sxfParkingSpace.getDepartmentId());
		from.setIsDeleted(sxfParkingSpace.getIsDeleted());
		from.setPlatformIsShare(sxfParkingSpace.getPlatformIsShare());
		from.setShareChangeTime(sxfParkingSpace.getShareChangeTime());
		from.setReserveTempCount(sxfParkingSpace.getReserveTempCount());
		from.setReserveTempMaxCount(sxfParkingSpace.getReserveTempMaxCount());
		from.setRankDirection(sxfParkingSpace.getRankDirection());
		from.setRankOrder(sxfParkingSpace.getRankOrder());
		from.setCreator(sxfParkingSpace.getCreator());
		from.setCreateTime(sxfParkingSpace.getCreateTime());
		from.setModifier(sxfParkingSpace.getModifier());
		from.setModifyTime(sxfParkingSpace.getModifyTime());
		from.setSpaceId(sxfParkingSpace.getSpaceId());

		return from;
	}

	
	public SxfParkingSpaceFrom findById(String id) {
		SxfParkingSpace entity = this.getOne(new QueryWrapper<SxfParkingSpace>().lambda()
				.eq(SxfParkingSpace::getId, id)
				);
		if(entity == null) return null;
		return transformationBean(entity);
	}
	
	public ResponseData remove(String id) {
		if(findById(id)== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfParkingSpace sxfParkingSpace = new SxfParkingSpace();
		sxfParkingSpace.setId(id);
		this.updateById(sxfParkingSpace);
		return ResponseData.success("删除成功");
	}
	
	public IPage pageList(Integer page, Integer size, SxfParkingSpaceFrom ibean) {
		return this.page(new Page(page, size), new QueryWrapper<SxfParkingSpace>().lambda()
				.eq(StringUtils.isNotEmpty(ibean.getPlCode()), SxfParkingSpace::getPlCode, ibean.getPlCode())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceCode()), SxfParkingSpace::getSpaceCode, ibean.getSpaceCode())
				.eq(StringUtils.isNotEmpty(ibean.getZoneCode()), SxfParkingSpace::getZoneCode, ibean.getZoneCode())
				.eq(StringUtils.isNotEmpty(ibean.getPlZoneInZoneCode()), SxfParkingSpace::getPlZoneInZoneCode, ibean.getPlZoneInZoneCode())
				.eq(StringUtils.isNotEmpty(ibean.getPropertyPerson()), SxfParkingSpace::getPropertyPerson, ibean.getPropertyPerson())
				.eq(StringUtils.isNotEmpty(ibean.getUserPerson()), SxfParkingSpace::getUserPerson, ibean.getUserPerson())
				.eq(StringUtils.isNotEmpty(ibean.getUserPhone()), SxfParkingSpace::getUserPhone, ibean.getUserPhone())
				.eq(StringUtils.isNotEmpty(ibean.getNature()), SxfParkingSpace::getNature, ibean.getNature())
				.eq(StringUtils.isNotEmpty(ibean.getIsShare()), SxfParkingSpace::getIsShare, ibean.getIsShare())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceType()), SxfParkingSpace::getSpaceType, ibean.getSpaceType())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceState()), SxfParkingSpace::getSpaceState, ibean.getSpaceState())
				.eq(StringUtils.isNotEmpty(ibean.getRemark()), SxfParkingSpace::getRemark, ibean.getRemark())
				.eq(ibean.getTransverseAxis() != null, SxfParkingSpace::getTransverseAxis, ibean.getTransverseAxis())
				.eq(ibean.getPortraiAxis() != null, SxfParkingSpace::getPortraiAxis, ibean.getPortraiAxis())
				.eq(StringUtils.isNotEmpty(ibean.getIsOccupy()), SxfParkingSpace::getIsOccupy, ibean.getIsOccupy())
				.eq(StringUtils.isNotEmpty(ibean.getSelfIsShare()), SxfParkingSpace::getSelfIsShare, ibean.getSelfIsShare())
				.eq(StringUtils.isNotEmpty(ibean.getSpacePosition()), SxfParkingSpace::getSpacePosition, ibean.getSpacePosition())
				.eq(ibean.getDepartmentId() != null, SxfParkingSpace::getDepartmentId, ibean.getDepartmentId())
				.eq(StringUtils.isNotEmpty(ibean.getIsDeleted()), SxfParkingSpace::getIsDeleted, ibean.getIsDeleted())
				.eq(StringUtils.isNotEmpty(ibean.getPlatformIsShare()), SxfParkingSpace::getPlatformIsShare, ibean.getPlatformIsShare())
				.eq(ibean.getShareChangeTime() != null, SxfParkingSpace::getShareChangeTime, ibean.getShareChangeTime())
				.eq(ibean.getReserveTempCount() != null, SxfParkingSpace::getReserveTempCount, ibean.getReserveTempCount())
				.eq(ibean.getReserveTempMaxCount() != null, SxfParkingSpace::getReserveTempMaxCount, ibean.getReserveTempMaxCount())
				.eq(StringUtils.isNotEmpty(ibean.getRankDirection()), SxfParkingSpace::getRankDirection, ibean.getRankDirection())
				.eq(ibean.getRankOrder() != null, SxfParkingSpace::getRankOrder, ibean.getRankOrder())
				.eq(ibean.getCreator() != null, SxfParkingSpace::getCreator, ibean.getCreator())
				.eq(ibean.getCreateTime() != null, SxfParkingSpace::getCreateTime, ibean.getCreateTime())
				.eq(ibean.getModifier() != null, SxfParkingSpace::getModifier, ibean.getModifier())
				.eq(ibean.getModifyTime() != null, SxfParkingSpace::getModifyTime, ibean.getModifyTime())
				.eq(ibean.getSpaceId() != null, SxfParkingSpace::getSpaceId, ibean.getSpaceId())
				);
	}
}
